import { Table, Pagination } from 'antd';
import axios from 'axios';
import { useState,useEffect } from "react"



const App = () => {

  let defaultCurrent = 1


  const columns = [
    {
      title: '标题',
      dataIndex: 'title',
      key: 'title',
    },
    {
      title: '分类',
      dataIndex: 'cateName',
      key: 'cateName',
    },
    {
      title: '作者',
      dataIndex: 'createBy',
      key: 'createBy',
    },
    {
      title: '阅读',
      dataIndex: 'views',
      key: 'views',
    },
    {
      title: '创建时间',
      dataIndex: 'createDate',
      key: 'createDate',
    },
    {
      title: '操作',
      dataIndex: '',
      key: '',
    },
  ];

  let [varState, setvarState] = useState({
    columns: columns,
    defaultCurrent: defaultCurrent,
    total: 0,
  })
  let [dataSourceState, setDataSourceState] = useState([])


  const getList = async () => {
    await axios.get(`/portal-service/pages/getList/` + varState.defaultCurrent).then(res => {
      let dataSource = res.data.data.result.map(item => {
        item.key = item.id;
        return item
      });
      setvarState({...varState,total:res.data.data.total})
      setDataSourceState(dataSource)
    })
  }

  const onChange = (current, pageSize) => {
    varState.defaultCurrent = current
    getList()
  };

  useEffect(() => {
    getList()
  }, [])



  return (
    <div>
      <Table dataSource={dataSourceState} columns={varState.columns} pagination={true} />
      <Pagination total={varState.total} defaultCurrent={varState.defaultCurrent} onChange={onChange} />
    </div>
  );
};
export default App;